home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / graphics / qrt.lzh / QRT.C < prev    next >
C/C++ Source or Header  |  1989-02-16  |  4KB  |  166 lines

  1. #include "header.h"
  2.  
  3. int GetObject();
  4. int RayTrace();
  5.  
  6.  
  7. /**********************************************************
  8.  
  9.                Test routine - unused
  10.  
  11.  **********************************************************/
  12.  
  13. #ifdef TESTS
  14.  
  15. Tree_Walker(obj,num)
  16.   OBJ_PTR obj;
  17.   int num;
  18. {
  19.   int x;
  20.  
  21.   for (x=0; x<num; x++) printf(" ");
  22.   printf("%d\n",obj->type);
  23.  
  24.   if (obj->child!=NULL)
  25.     Tree_Walker(obj->child,num+2);
  26.  
  27.   if (obj->nextobj!=NULL)
  28.     Tree_Walker(obj->nextobj,num);
  29. }
  30.  
  31. #endif
  32.  
  33.  
  34. /**********************************************************
  35.  
  36.     Initialize some observer data, like up and right
  37.     vectors, focal length, etc.
  38.  
  39.  **********************************************************/
  40.  
  41. Setup_Observer() {
  42.  
  43.   if (THEWORLD.observer==NULL) Error(NO_OBSERVER,001);
  44.  
  45.   Normalize(&((THEWORLD.observer)->vect1));
  46.   VectEQ(&(THEWORLD.obsup),&((THEWORLD.observer)->vect2));
  47.  
  48.   CrossProd(&(THEWORLD.obsright),             /* right = up x dir */
  49.             &(THEWORLD.obsup),
  50.             &((THEWORLD.observer)->vect1));
  51.  
  52.   CrossProd(&(THEWORLD.obsup),                /* up = dir x right */
  53.             &((THEWORLD.observer)->vect1),
  54.             &(THEWORLD.obsright));
  55.  
  56.   Normalize(&(THEWORLD.obsup));
  57.   Normalize(&(THEWORLD.obsright));
  58.  
  59.   THEWORLD.flength*=5;
  60. }
  61.  
  62.  
  63. /**********************************************************
  64.  
  65.          Initialize the world and assign defaults
  66.  
  67.  **********************************************************/
  68.  
  69. init_world() {                     /* make a universe */
  70.   THEWORLD.stack      =
  71.   THEWORLD.observer   =
  72.   THEWORLD.instances  =
  73.   THEWORLD.sky        =
  74.   THEWORLD.lamps      = NULL;
  75.   THEWORLD.patlist    = NULL;
  76.   THEWORLD.outfile    = NULL;
  77.   THEWORLD.objcount   = 0;
  78.   THEWORLD.lampcount  = 0;
  79.   THEWORLD.flength    = 50;
  80.   THEWORLD.first_scan = 0;
  81.   THEWORLD.last_scan  = YSIZE-1;
  82.  
  83.   THEWORLD.skycolor_zenith.r =
  84.   THEWORLD.skycolor_zenith.b =
  85.   THEWORLD.skycolor_zenith.g =
  86.   THEWORLD.skycolor_horiz.r  =
  87.   THEWORLD.skycolor_horiz.g  =
  88.   THEWORLD.skycolor_horiz.b  = 0;
  89.  
  90.   THEWORLD.ray_intersects  =
  91.   THEWORLD.pixels_hit      =
  92.   THEWORLD.primary_traced  =
  93.   THEWORLD.to_lamp         =
  94.   THEWORLD.refl_trans      =
  95.   THEWORLD.bbox_intersects =
  96.   THEWORLD.pattern_matches =
  97.   THEWORLD.intersect_tests = 0;
  98.  
  99.   THEWORLD.globindex = 1.00;   /* global index of refraction */
  100.  
  101.   def.cinfo.trans.r  =         /* default transmittion */
  102.   def.cinfo.trans.g  =
  103.   def.cinfo.trans.b  = 0;
  104.  
  105.   def.cinfo.mirror.r =         /* default reflection */
  106.   def.cinfo.mirror.g =
  107.   def.cinfo.mirror.b = 0;
  108.  
  109.   def.cinfo.amb.r    =         /* default ambiant light */
  110.   def.cinfo.amb.g    =
  111.   def.cinfo.amb.b    = 25;
  112.  
  113.   def.cinfo.diff.r   =         /* default diffuse light */
  114.   def.cinfo.diff.g   =
  115.   def.cinfo.diff.b   = CNUM;
  116.  
  117.   def.cinfo.density.x=
  118.   def.cinfo.density.y=
  119.   def.cinfo.density.z= .01;    /* default glass density */
  120.  
  121.   def.cinfo.fuzz     = 0;
  122.   def.cinfo.index    = CNUM;
  123.   def.cinfo.dither   = 3;
  124.   def.cinfo.reflect  = 0;
  125.   def.cinfo.sreflect = 10;
  126.  
  127.   def.shadow      = TRUE;      /* shadows */
  128.   def.vlamp       = FALSE;     /* no visible lamps */
  129.   def.int_x       =            /* no interpolation */
  130.   def.int_y       = 1;
  131.   def.threshold   = .1;        /* threshold at 10 percent */
  132.   def.ithreshold  = def.threshold * CNUM;
  133. }
  134.  
  135.  
  136. /**********************************************************
  137.  
  138.      Call other stuff to load world and generate image
  139.  
  140.  **********************************************************/
  141.  
  142. main()
  143. {
  144.   printf("Quick Ray Trace: Copyright 1988 Steve Koren\nVersion 1.4\n");
  145.  
  146.   init_world();
  147.  
  148.   if (!LoadWorld()) Error(SYNTAX_ERROR,002);
  149.  
  150.   Make_Bbox(THEWORLD.stack);     /* make bboxes */
  151.   Do_Precomp(THEWORLD.stack);    /* precompute stuff */
  152.  
  153.   fclose(stdin);
  154.  
  155.   Setup_Observer();
  156.  
  157.   Open_File();
  158.     Screen_Trace();
  159.   Close_File();
  160.  
  161.   World_Stats();
  162.   fclose(stdout);
  163.   return(NULL);
  164. }
  165.  
  166.